/***********************************************************************  
 *   @package：cn.wj.base.util，@class-name：PropertiesLoader.java   
 *   @copyright     Copyright:   2015-2016     
 *   @creator       wenjie 
 *   @create-time   2016年1月10日   下午9:19:29   
 *   @revision      $Id: 1.0    
 ***********************************************************************/
package cn.wj.base.util;

import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.Properties;

public class PropertiesLoader {
	private Properties properties;

	private static class LazyLoader {
		private static final PropertiesLoader loader = new PropertiesLoader();
	}

	private PropertiesLoader() {
		properties = new Properties();
		try {
			properties.load(this.getClass().getClassLoader().getResourceAsStream("config/config.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static final PropertiesLoader getInstance() {
		return LazyLoader.loader;
	}

	private Properties getProperties() {
		return properties;
	}

	public String getValueByKey(String key) {
		return getProperties().getProperty(key);
	}

	public Integer getByIntegerKey(String key) {
		String value = getValueByKey(key);
		if (value == null) {
			throw new NoSuchElementException();
		}
		return Integer.valueOf(value);
	}

	public String dbClass() {
		return getProperties().getProperty("DB_CLASS");
	}

	public String dbUrl() {
		return getProperties().getProperty("DB_URL");
	}

	public String dbUser() {
		return getProperties().getProperty("DB_USER");
	}

	public String dbPassword() {
		return getProperties().getProperty("DB_PASSWORD");
	}

	public String staticResources() {
		return getProperties().getProperty("Static_Resources");
	}

	public Integer getMAXPool() {
		String value = getValueByKey("MAXPool");
		if (value == null) {
			throw new NoSuchElementException();
		}
		return Integer.valueOf(value);
	}

	public Integer getMinPool() {
		String value = getValueByKey("MinPool");
		if (value == null) {
			throw new NoSuchElementException();
		}
		return Integer.valueOf(value);
	}

}